package woaini.fenger.task;

import lombok.extern.slf4j.Slf4j;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.QuartzJobBean;
import org.springframework.stereotype.Component;
import woaini.fenger.command.hitokoto.api.HitokotoApi;
import woaini.fenger.command.hitokoto.api.HitokotoResDTO;
import woaini.fenger.core.bot.base.Bot;
import woaini.fenger.core.bot.enums.PLatFormEnum;
import woaini.fenger.core.bot.event.Messages;
import woaini.fenger.core.bot.id.ID;
import woaini.fenger.core.bot.manager.BotManager;
import woaini.fenger.core.bot.manager.key.BotKey;
import woaini.fenger.core.task.anno.BotTask;

@Component
@Slf4j
@DisallowConcurrentExecution
@BotTask(name = "日常问候", description = "每天bb你")
public class DailyGreetings extends QuartzJobBean {

  @Autowired BotManager botManager;

  @Override
  protected void executeInternal(JobExecutionContext context){
    Bot bot = botManager.getBot(new BotKey(ID.of("355242685"), PLatFormEnum.QQ));

    //获取一言
    HitokotoResDTO resDTO = HitokotoApi.get(null);

    StringBuilder stringBuilder = new StringBuilder();
    stringBuilder.append(resDTO.getHitokoto()).append("\r\n");
    stringBuilder
            .append("——")
            .append(resDTO.getFrom_who())
            .append("<")
            .append(resDTO.getFrom())
            .append(">");
    bot.getBotAdapter().sendGroupMsg(ID.of("856337734"), new Messages().text(stringBuilder.toString()), false);
  }
}
